/**
 * Copyright (C) 2010 Sergey Grigoriev <s.a.grigoriev@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.junit.Assert;


def private verifyReport(fileName, expected) {
  def reportFile = [project.build.directory, 'surefire-reports', fileName].join(File.separator)
  def actualValues = collectStatistics(reportFile)
  Assert.assertEquals(expected, actualValues)
  new File(reportFile).delete()
  Assert.assertFalse('Could not cleanup file', new File(reportFile).exists())
}

def private collectStatistics(file) {
  def total = 0;
  def errors = 0;
  def failures = 0;

  print "parsing  $file ... "
  def dom = new XmlParser().parse(file)
  println "done"
  dom.testcase.each {
    if (it.error) {
      errors++
    } else if (it.failure) {
      failures++
    }
    total++
  }
  return [total, failures, errors]
}

[
        'TEST-net.gmf.examples.surefire.TestCase1.xml': [2, 0, 1],
        'TEST-net.gmf.examples.surefire.TestCase2.xml': [2, 1, 0],
        'TEST-net.gmf.examples.surefire.TestCase3.xml': [2, 0, 0]
].each { key, value ->

  verifyReport(key, value)
}


